﻿using Engine;
using System.Xml.Linq;

namespace CreatorWandModAPI
{
    public static class CreatorMain
    {
        public enum CreateType
        {
            X,
            Y,
            Z
        }

        public static class Math
        {
            public static void StarttoEnd(ref Point3 Start, ref Point3 End)
            {
                if (Start.X > End.X)
                {
                    (Start.X, End.X) = (End.X, Start.X);
                }

                if (Start.Y > End.Y)
                {
                    (Start.Y, End.Y) = (End.Y, Start.Y);
                }

                if (Start.Z > End.Z)
                {
                    (Start.Z, End.Z) = (End.Z, Start.Z);
                }
            }

            public static void StartEnd(ref Point3 Start, ref Point3 End)
            {
                if (Start.X < End.X)
                {
                    (Start.X, End.X) = (End.X, Start.X);
                }

                if (Start.Y < End.Y)
                {
                    (Start.Y, End.Y) = (End.Y, Start.Y);
                }

                if (Start.Z < End.Z)
                {
                    (Start.Z, End.Z) = (End.Z, Start.Z);
                }
            }
        }

        public static List<Point3> Position;

        public static string version = "3-Series";

        public static int Numversion = 105172;

        public static int[] Sumnumversion = new int[]
        {
            104910,
           104590,
           105172
        };

        public static int[] Donotnumversion = new int[]
        {
            902021003,
            902021011,
            902021002,
            902021012,
            902021013,
            922107401,
            922107502,
            922107504,
            922117620
        };

        public static string password = "456321";

        public static bool canUse = true;

        public static bool professional = false;

        public static readonly string CacheDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Cache");

        private static string sdcard;

        public static readonly string Export_wMod_Directory = Path.Combine(Sdcard, "wMod");

        public static readonly string Export_oMod_Directory = Path.Combine(Sdcard, "oMod");

        public static readonly string Export_CopyFile_Directory = Path.Combine(Sdcard, "Copy");

        public static readonly string Export_OnekeyFile_Directory = Path.Combine(Sdcard, "OneKey");

        public static readonly string OneKeyFile = Path.Combine(CacheDirectory, "CacheFile.od");

        public static readonly string CopyFile = Path.Combine(CacheDirectory, "CacheFile.cd");

        public static readonly string SpecialCopyFile = Path.Combine(CacheDirectory, "CacheFile.sd");

        public static readonly string Export_ModFile_Directory = Path.Combine(Sdcard, "Mod");

        public static string SCLanguage_Directory = Path.Combine(Sdcard, "Mod", "CreatorAPI" + version + ".xml");

        public static bool Penetrate = false;

        public static List<int> PenetrateBlocksID = new List<int>();

        public static bool LightWorld = false;

        public static List<int> LightWorldBlockID = new List<int>();

        public static string Sdcard
        {
            get
            {
                if (sdcard != null) return sdcard;
                sdcard = Environment.OSVersion.Platform.ToString() switch
                {
                    "Android" or "Unix" => Path.Combine(Storage.GetSystemPath("config:/")),
                    _ => Path.Combine(Directory.GetCurrentDirectory(), "CreatorMod")
                };
                return sdcard;
            }
        }

        public static string Language_Directory
        {
            get
            {
                string rOSversion = Environment.OSVersion.Platform.ToString() switch
                {
                    "Android" or "Unix" => Path.Combine(Storage.GetSystemPath("config:/"), "ModSettings.xml"),
                    _ => Path.Combine(Directory.GetCurrentDirectory(), "ModSettings.xml")
                };
                return rOSversion;
            }
        }

        public static string Display_Key_Dialog(string Key)
        {
            foreach (XElement item in CreatorAPI.CreatorDisplayDataDialog)
            {
                if (item.Attribute("Text").Value == Key)
                {
                    return item.Attribute("DisplayName").Value.Replace("\\n", "\n");
                }
            }

            return Key;
        }

        public static string Display_Key_UI(string Language, string Name, string Key)
        {
            foreach (XElement item in CreatorAPI.CreatorDisplayDataUI)
            {
                if (item.Name.ToString() != Name)
                {
                    continue;
                }
                {
                    foreach (XElement item2 in from xe in item.Elements("CreatorDisplayData")
                                               where xe.Attribute("Language").Value == Language
                                               select xe)
                    {
                        if (item2.Attribute("Text").Value == Key)
                        {
                            return item2.Attribute("DisplayName").Value.Replace("\\n", "\n");
                        }
                    }

                    return Key;
                }
            }

            return Key;
        }

        public static string Path_str(string path1, string path2)
        {
            return path1 + "/" + path2;
        }
    }
}